import Taro from '@tarojs/taro-rn';
import * as tslib_1 from "tslib";
import React from 'react';
import { Component } from "@tarojs/taro-rn";
import { View, Image, Text } from "@tarojs/components-rn";
import { AtToast } from "taro-ui";
import { toJS } from 'mobx';
import { inject, observer } from "@tarojs/mobx-rn";
import Report from "../../components/Report";
import PageFooterInfo from "../../components/PageFooterInfo";
import { getRuntime, servicePhoneNumber, subtime } from "../../utils/common";
import position_detailStyleSheet from "./position_detail_styles";

import icon_47 from '../../assets/img/icon_47.png';
import iconCollection from "../../assets/img/icon_03.png";
import iconCollection_on from "../../assets/img/icon_03_on.png";
var _styleSheet = position_detailStyleSheet;
let Detail = class Detail extends Component {
  constructor(props) {
    super(props);
    this.state = {
      isVip: false,
      info: {},
      samePositionInfo: [],
      isCollection: false,
      isTips: false,
      tipsText: ''
    };
  }
  componentWillMount() {
    Taro.setNavigationBarTitle({ title: '职位详情' });
    let id = this.$router.params.id;
    if (!id) {
      getRuntime().navigateBack();
    }
    this.getInfomationInfos(parseInt(id));
    let userInfo = getRuntime().getUserInfo();
    //console.log(userInfo)
    if (userInfo && userInfo.agencyLevel > 0) {
      this.setState({ isVip: true });
    }
    let isCollection = parseInt(this.$router.params.isCollection);
    if (isCollection === 1) {
      this.setState({ isCollection: true });
    }
    this.getSamePositionInfo();
  }
  componentDidShow() {}
  // 获取相关工作职位
  getSamePositionInfo() {
    let samePositionInfo = getRuntime().getStorage('positionInfo');
    let tmp = [];
    if (samePositionInfo.length > 0) {
      samePositionInfo.map(item => {
        if (item.publicationType === 3) {
          tmp.push(item);
        }
      });
    }
    this.setState({
      samePositionInfo: tmp
    });
  }
  getInfomationInfos(formId) {
    let { homeStore } = this.props.stores;
    homeStore.getInfomationInfos({
      formId,
      callback: res => {
        //console.log(home)
        let isCollection = parseInt(this.$router.params.isCollection) === 1 ? true : toJS(res.isCollection);
        this.setState({
          info: toJS(res),
          isCollection
        });
      }
    });
  }
  handelRouter(url = '/pages/index/index') {
    getRuntime().navigateTo(url);
  }
  toggleCollection() {
    if (!getRuntime().getToken()) {
      Taro.showModal({
        title: '请先进行登录',
        content: '',
        confirmText: '前往登录'
      }).then(res => {
        if (res.confirm) {
          getRuntime().navigateTo('/pages/login/login');
        }
      });
      return;
    }
    let { userStore } = this.props.stores;
    this.setState({
      isCollection: !this.state.isCollection
    }, () => {
      if (this.state.isCollection) {
        // 收藏
        userStore.saveUserCollection({
          form: {
            informationsId: parseInt(this.$router.params.id),
            userCollectionType: 2
          },
          callback: () => {
            //this.setState({isTips: true, tipsText: '收藏成功~'})
          }
        });
      } else {
        // 取消收藏
        userStore.cancelUserCollection({
          form: {
            id: parseInt(this.$router.params.id),
            userCollectionType: '2'
          },
          callback: () => {
            //this.setState({isTips: true, tipsText: '取消收藏成功~'})
          }
        });
      }
    });
  }
  componentDidHide() {
    // Taro.removeStorageSync('positionInfo')
  }
  makePhone(phone) {
    if (!phone) {
      phone = servicePhoneNumber;
      return;
    }
    getRuntime().makePhoneCall(phone);
  }
  render() {
    let { isVip, info, samePositionInfo, isCollection, isTips, tipsText } = this.state;
    return <View style={_styleSheet["personnel-detail"]}>
        <View style={_styleSheet["list-07-item"]}>
          <View style={_styleSheet["item-title"]}>
            <View style={_styleSheet["title"]}>
              {info.positionName}
            </View>
            <View onClick={this.toggleCollection.bind(this)} style={_styleSheet["address"]}>
              {!isCollection && <Image src={iconCollection} style={_styleSheet["icon-collection"]} />}
              {isCollection && <Image src={iconCollection_on} style={_styleSheet["icon-collection"]} />}
              <Text style={_styleSheet["name-collection"]}>收藏</Text>
              <AtToast isOpened={isTips} text={tipsText} />
            </View>
          </View>
          <Text style={_styleSheet["op"]}>{info.monthlyPay}</Text>
          <View style={_styleSheet["item-info"]}>
            <View style={_styleSheet["info"]}>
              <Text style={_styleSheet["i"]}>发布：{subtime(info.creationTime)}</Text>
            </View>
            <View style={_styleSheet["btn-view"]}>
              浏览{info.numberOfVisits}人
            </View>
          </View>
        </View>
        <View style={_styleSheet["interval"]} />

        <View style={_styleSheet["column-title"]}>
          <Text style={_styleSheet["column-name"]}>招聘信息</Text>
        </View>
        <View style={_styleSheet["item-lawyer"]}>
            <View style={_styleSheet["line"]}>
              <Text style={_styleSheet["title"]}>招聘人数：</Text>
              <Text style={_styleSheet["name"]}>{info.recruitment}人</Text>
            </View>
            <View style={_styleSheet["line"]}>
              <Text style={_styleSheet["title"]}>学历：</Text>
              <Text style={_styleSheet["name"]}>{info.education}</Text>
            </View>
            <View style={_styleSheet["line"]}>
              <Text style={_styleSheet["title"]}>工作经验：</Text>
              <Text style={_styleSheet["name"]}>{info.workExperience}</Text>
            </View>
            <View style={_styleSheet["line"]}>
              <Text style={_styleSheet["title"]}>职称：</Text>
              <Text style={_styleSheet["name"]}>{info.technicalTitle}</Text>
            </View>
            <View style={_styleSheet["line"]}>
              <Text style={_styleSheet["title"]}>月薪：</Text>
              <Text style={_styleSheet["name"]}>{info.monthlyPay}</Text>
            </View>
            <View style={_styleSheet["line"]}>
              <Text style={_styleSheet["title"]}>工作性质：</Text>
              <Text style={_styleSheet["name"]}>{info.jobNature}</Text>
            </View>
            <View style={_styleSheet["line"]}>
              <Text style={_styleSheet["title"]}>工作地点：</Text>
              <Text style={_styleSheet["name"]}>{info.address}</Text>
            </View>
        </View>
        <View style={_styleSheet["interval"]} />

        <View style={_styleSheet["column-title"]}>
          <Text style={_styleSheet["column-name"]}>职位简介</Text>
        </View>
        <View style={_styleSheet["item-lawyer-desc"]}>
          {info.description}
        </View>
        <View style={_styleSheet["interval"]} />
        <View style={_styleSheet["column-title"]}>
          <Text style={_styleSheet["column-name"]}>企业简介</Text>
        </View>
        <View style={_styleSheet["item-lawyer"]}>
          <View style={_styleSheet["line"]}>
            <Text style={_styleSheet["title"]}>企业名称：</Text>
            <Text style={_styleSheet["name"]}>{info.companyName}</Text>
          </View>
          <View style={_styleSheet["line"]}>
            <Text style={_styleSheet["title"]}>企业性质：</Text>
            <Text style={_styleSheet["name"]}>{info.natureOfTheFirm}</Text>
          </View>
          <View style={_styleSheet["line"]}>
            <Text style={_styleSheet["title"]}>企业规模：</Text>
            <Text style={_styleSheet["name"]}>{info.enterpriseScale}</Text>
          </View>
          <View style={_styleSheet["line"]}>
            <Text style={_styleSheet["title"]}>企业地址：</Text>
            <Text style={_styleSheet["name"]}>{info.area}</Text>
          </View>
          <View style={_styleSheet["line"]}>
            <Text style={_styleSheet["title"]}>企业简介：</Text>
            <Text style={_styleSheet["name"]}>{info.enterpriseIntroduce}</Text>
          </View>
        </View>
        <View style={_styleSheet["interval"]} />

        <View style={_styleSheet["column-title"]}>
          <Text style={_styleSheet["column-name"]}>联系方式</Text>
        </View>
        <View style={_styleSheet["item-lawyer"]}>
          <View style={_styleSheet["line"]}>
            <Text style={_styleSheet["title"]}>联系人：</Text>
            <Text style={_styleSheet["name"]}>{info.contactsName}</Text>
          </View>
          <View style={_styleSheet["line"]}>
            <Text style={_styleSheet["title"]}>联系电话：</Text>
            <Text style={_styleSheet["name"]}>{info.phoneNumnber}</Text>
          </View>
          <View style={_styleSheet["line"]}>
            <Text style={_styleSheet["title"]}>微信号：</Text>
            <Text style={_styleSheet["name"]}>{info.wechatNumber}</Text>
          </View>
          <View style={_styleSheet["line"]}>
            <Text style={_styleSheet["title"]}>QQ号：</Text>
            <Text style={_styleSheet["name"]}>{info.qqNumber}</Text>
          </View>
        </View>
        <View style={_styleSheet["interval"]} />

        {samePositionInfo.length > 0 && <View style={[_styleSheet["column-title"], _styleSheet["content-30"]]}>
             <Text style={_styleSheet["column-name"]}>其他职位</Text>
             <Text onClick={this.handelRouter.bind(this, '/pages/newest/index')} style={_styleSheet["column-more"]}>查看更多 > </Text>
          </View>}
        {samePositionInfo.length > 0 && <View style={_styleSheet["list-06"]}>
            {samePositionInfo.map(item => {
          return <View onClick={this.handelRouter.bind(this, '/pages/newest/position_detail?id=' + item.id)} style={_styleSheet["list-06-item"]}>
                    <View style={_styleSheet["item-title"]}>
                      <View style={_styleSheet["title"]}>
                        {item.positionName}
                        <Text style={_styleSheet["label"]}>{item.jobNature}</Text>
                      </View>
                      <View style={_styleSheet["address"]}>{item.address}</View>
                    </View>
                    <View style={_styleSheet["item-info"]}>
                      <View style={_styleSheet["info"]}>
                        <Text style={_styleSheet["op"]}>{item.monthlyPay}</Text>
                        <Text style={_styleSheet["i"]}>{item.education}</Text>
                        <Text style={[_styleSheet["i"], _styleSheet["brnone"]]}>{item.recruitment}人</Text>
                      </View>
                      <View onClick={this.handelRouter.bind(this, '/pages/newest/position_detail?id=' + item.id)} style={_styleSheet["btn-view"]}>
                        查看
                      </View>
                    </View>
                  </View>;
        })}
          </View>}

        <View style={_styleSheet["interval"]} />
        <Report />
        <View style={_styleSheet["interval"]} />
        <PageFooterInfo />
        <View style={_styleSheet["footer-block"]} />
        <View style={_styleSheet["position-footer-btn"]}>
          <View style={[_styleSheet["phone"], { width: '100%' }]} onClick={this.makePhone.bind(this)}>
            <Image src={icon_47} style={_styleSheet["icon"]} />
            <View>电话资讯</View>
          </View>
          
        </View>
      </View>;
  }
};
Detail = tslib_1.__decorate([inject("stores"), observer], Detail);
export default Detail;